const nextConfig = {
  async headers() {
    return [
      {
        source: "/api/:path*",
        headers: [
          { key: "Access-Control-Allow-Credentials", value: "true" },
          { key: "Access-Control-Allow-Origin", value: "http://localhost:3000" },
          { key: "Access-Control-Allow-Methods", value: "GET,DELETE,PATCH,POST,PUT,OPTIONS" },
          {
            key: "Access-Control-Allow-Headers",
            value: "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, x-user-id",
          },
        ],
      },
    ];
  },
  trailingSlash: false, // 默认就是 false
  async redirects() {
    return [
      {
        source: "/api/:path*/",
        destination: "/api/:path*",
        permanent: false, // 用 302 而不是 308，避免某些客户端不兼容
      },
    ];
  },
};

module.exports = nextConfig;
